package com.vecspace.dayu.code.pojo;

import java.util.Date;
import java.util.Map;
import java.math.BigDecimal;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.base.CaseFormat;
import com.vecspace.data.model.IdEntity;
import com.vecspace.data.model.RowMapper;
import com.vecspace.dayu.code.consts.ColumnType;
import com.vecspace.dayu.code.consts.FormElementType;
import com.vecspace.dayu.code.model.SrcCodeUtils;
import com.vecspace.dicttable.DictAll;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.Polymorphism;
import org.hibernate.annotations.PolymorphismType;
import org.hibernate.annotations.Type;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

/** DAYU-字段定义
 * @author wanghua
 */
@Entity
@Polymorphism(type = PolymorphismType.EXPLICIT)
@Table(name = "DAYU_CODE_DATA_COLUMN")
public class DataColumn implements IdEntity, java.io.Serializable {

	private static final long serialVersionUID = 3938984989497500956L;
	public DataColumn(){
	}
	private Long id;
	/**逻辑ID*/
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name = "ID")
	public Long getId(){
		return id;
	}
	/**逻辑ID*/
	public void setId(Long value){
		this.id = value;
	}

	private Long datatableId;
	/**表ID*/
	@Column(name = "DATATABLE_ID")
	public Long getDatatableId(){
		return datatableId;
	}
	/**表ID*/
	public void setDatatableId(Long value){
		this.datatableId = value;
	}

	private String columnName;
	/**字段名*/
	@Column(name = "COLUMN_NAME")
	public String getColumnName(){
		return columnName;
	}
	/**字段名*/
	public void setColumnName(String value){
		this.columnName = value;
	}

	private String columnCaption;
	/**字段中文名*/
	@Column(name = "COLUMN_CAPTION")
	public String getColumnCaption(){
		return columnCaption;
	}
	/**字段中文名*/
	public void setColumnCaption(String value){
		this.columnCaption = value;
	}

	private String columnAliasName;
	/**字段别名*/
	@Column(name = "COLUMN_ALIAS_NAME")
	public String getColumnAliasName(){
		return columnAliasName;
	}
	/**字段别名*/
	public void setColumnAliasName(String value){
		this.columnAliasName = value;
	}
	
	private Integer valueUnique;//

	/**值是否唯一*/
	@Column(name = "VALUE_UNIQUE")
	public Integer getValueUnique() {
		return valueUnique;
	}
	/**值是否唯一*/
	public void setValueUnique(Integer valueUnique) {
		this.valueUnique = valueUnique;
	}
	@Transient
	public boolean getIsUniqueColumn() {
		return valueUnique != null && valueUnique.equals(1);
	}

	private String dataType;
	/**数据类型*/
	@Column(name = "DATA_TYPE")
	public String getDataType(){
		return dataType;
	}
	/**数据类型*/
	public void setDataType(String value){
		this.dataType = value;
	}

	private Integer dataLength;
	/**数据长度*/
	@Column(name = "DATA_LENGTH")
	public Integer getDataLength(){
		return dataLength;
	}
	/**数据长度*/
	public void setDataLength(Integer value){
		this.dataLength = value;
	}

	private Integer dataScale;
	/**小数位数*/
	@Column(name = "DATA_SCALE")
	public Integer getDataScale(){
		return dataScale;
	}
	/**小数位数*/
	public void setDataScale(Integer value){
		this.dataScale = value;
	}

	private String unit;
	/**数量单位*/
	@Column(name = "UNIT_")
	public String getUnit(){
		return unit;
	}
	/**数量单位*/
	public void setUnit(String value){
		this.unit = value;
	}

	private String custDataType;
	/**自定义数据类型*/
	@Column(name = "CUST_DATA_TYPE")
	public String getCustDataType(){
		return custDataType;
	}
	/**自定义数据类型*/
	public void setCustDataType(String value){
		this.custDataType = value;
	}

	private Boolean isSearchField;
	/**是否查询项,0否，1是*/
	@Column(name = "IS_SEARCH_FIELD")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getIsSearchField() {
		return isSearchField;
	}
	public void setIsSearchField(Boolean searchField) {
		isSearchField = searchField;
	}

	private String searchValueType;
	/**查询值类型,date-year,date-month,multi*/
	@Column(name = "SEARCH_VALUE_TYPE")
	public String getSearchValueType() {
		return searchValueType;
	}
	public void setSearchValueType(String searchValueType) {
		this.searchValueType = searchValueType;
	}

	private Boolean isGroupby;
	/**是否分组*/
	@Column(name = "IS_GROUPBY")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getIsGroupby() {
		return isGroupby;
	}
	public void setIsGroupby(Boolean groupby) {
		isGroupby = groupby;
	}

	private String aggregateFunc;
	/**聚合函数，多个函数用逗号分割*/
	@Column(name = "AGGREGATE_FUNC")
	public String getAggregateFunc() {
		return aggregateFunc;
	}
	public void setAggregateFunc(String aggregateFunc) {
		this.aggregateFunc = aggregateFunc;
	}

	private Boolean required;
	/**是否必填，0否，1是*/
	@Column(name = "REQUIRED")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getRequired() {
		return required;
	}
	public void setRequired(Boolean required) {
		this.required = required;
	}

	private String validationRules;
	/**验证规则,多个规则分号分隔，codetype=dayu-CODE-016*/
	@Column(name = "VALIDATION_RULES")
	public String getValidationRules() {
		return validationRules;
	}
	public void setValidationRules(String validationRules) {
		this.validationRules = validationRules;
	}

	private Boolean cellMenu;
	/**下拉菜单,0否，1是*/
	@Column(name = "CELL_MENU")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getCellMenu() {
		return cellMenu;
	}
	public void setCellMenu(Boolean cellMenu) {
		this.cellMenu = cellMenu;
	}

	private Integer minCharLength;
	/**最大字符数*/
	@Column(name = "MIN_CHAR_LENGTH")
	public Integer getMinCharLength(){
		return minCharLength;
	}
	/**最大字符数*/
	public void setMinCharLength(Integer value){
		this.minCharLength = value;
	}

	private Integer maxCharLength;
	/**最少字符数*/
	@Column(name = "MAX_CHAR_LENGTH")
	public Integer getMaxCharLength(){
		return maxCharLength;
	}
	/**最少字符数*/
	public void setMaxCharLength(Integer value){
		this.maxCharLength = value;
	}

	private BigDecimal maxValue;
	/**最大值*/
	@Column(name = "MAX_VALUE")
	public BigDecimal getMaxValue(){
		return maxValue;
	}
	/**最大值*/
	public void setMaxValue(BigDecimal value){
		this.maxValue = value;
	}

	private BigDecimal minValue;
	/**最小值*/
	@Column(name = "MIN_VALUE")
	public BigDecimal getMinValue(){
		return minValue;
	}
	/**最小值*/
	public void setMinValue(BigDecimal value){
		this.minValue = value;
	}

	private String codeType;
	/**代码类型*/
	@Column(name = "CODE_TYPE")
	public String getCodeType(){
		return codeType;
	}
	/**代码类型*/
	public void setCodeType(String value){
		this.codeType = value;
	}

	private String refTableName;
	/**参考表名*/
	@Column(name = "REF_TABLE_NAME")
	public String getRefTableName(){
		return refTableName;
	}
	/**参考表名*/
	public void setRefTableName(String value){
		this.refTableName = value;
	}

	private String refIdColumn;
	/**参考表ID字段*/
	@Column(name = "REF_ID_COLUMN")
	public String getRefIdColumn(){
		return refIdColumn;
	}
	/**参考表ID字段*/
	public void setRefIdColumn(String value){
		this.refIdColumn = value;
	}

	private String refNameColumn;
	/**参考表名称字段*/
	@Column(name = "REF_NAME_COLUMN")
	public String getRefNameColumn(){
		return refNameColumn;
	}
	/**参考表名称字段*/
	public void setRefNameColumn(String value){
		this.refNameColumn = value;
	}

	private String refNameColumnAliasName;
	/**参考表名称字段别名*/
	@Column(name = "REF_NAME_COLUMN_ALIAS_NAME")
	public String getRefNameColumnAliasName(){
		return refNameColumnAliasName;
	}
	/**参考表名称字段别名*/
	public void setRefNameColumnAliasName(String value){
		this.refNameColumnAliasName = value;
	}
	
	@Transient
	public String getRefColumnInfo() {
		if(StringUtils.isBlank(refTableName) || StringUtils.isBlank(refIdColumn)) return "";
		return refTableName + "." + refIdColumn + ", " + refNameColumn + " " + refNameColumnAliasName;
	}

	private String charsetType;
	/**字符集*/
	@Column(name = "CHARSET_TYPE")
	public String getCharsetType(){
		return charsetType;
	}
	/**字符集*/
	public void setCharsetType(String value){
		this.charsetType = value;
	}

	private Integer ordnum;
	/**顺序号*/
	@Column(name = "ORDNUM")
	public Integer getOrdnum(){
		return ordnum;
	}
	/**顺序号*/
	public void setOrdnum(Integer value){
		this.ordnum = value;
	}

	private Date createTime;
	/**记录创建时间*/
	@JsonIgnore(true)
	@Column(name = "CREATE_TIME")
	public Date getCreateTime(){
		return createTime;
	}
	/**记录创建时间*/
	public void setCreateTime(Date value){
		this.createTime = value;
	}
	@Transient
	@JsonIgnore(true)
	public String getCreateTimeStr(){
		if(createTime == null){
			return "";
		}
		String exp = "yyyy-MM-dd";
		String timestr = new java.text.SimpleDateFormat(exp).format(createTime);
		return timestr;
	}

	private String createUser;
	/**记录创建人ID*/
	@Column(name = "CREATE_USER")
	public String getCreateUser(){
		return createUser;
	}
	/**记录创建人ID*/
	public void setCreateUser(String value){
		this.createUser = value;
	}

	
	public void parseFrom(Map<String, Object> row){
		RowMapper rowMapper = new RowMapper(row);
		this.id = rowMapper.getLong("ID");
		this.datatableId = rowMapper.getLong("DATATABLE_ID");
		this.columnName = rowMapper.getString("COLUMN_NAME");
//		this.columnType = rowMapper.getString("COLUMN_TYPE");
		this.columnCaption = rowMapper.getString("COLUMN_CAPTION");
		this.columnAliasName = rowMapper.getString("COLUMN_ALIAS_NAME");
		this.dataType = rowMapper.getString("DATA_TYPE");
		this.dataLength = rowMapper.getInteger("DATA_LENGTH");
		this.dataScale = rowMapper.getInteger("DATA_SCALE");
		this.unit = rowMapper.getString("UNIT_");
		this.custDataType = rowMapper.getString("CUST_DATA_TYPE");
		this.minCharLength = rowMapper.getInteger("MIN_CHAR_LENGTH");
		this.maxCharLength = rowMapper.getInteger("MAX_CHAR_LENGTH");
		this.maxValue = rowMapper.getBigDecimal("MAX_VALUE");
		this.minValue = rowMapper.getBigDecimal("MIN_VALUE");
		this.codeType = rowMapper.getString("CODE_TYPE");
		this.refTableName = rowMapper.getString("REF_TABLE_NAME");
		this.refIdColumn = rowMapper.getString("REF_ID_COLUMN");
		this.refNameColumn = rowMapper.getString("REF_NAME_COLUMN");
		this.refNameColumnAliasName = rowMapper.getString("REF_NAME_COLUMN_ALIAS_NAME");
		this.charsetType = rowMapper.getString("CHARSET_TYPE");
		this.ordnum = rowMapper.getInteger("ORDNUM");
		this.createTime = rowMapper.getDate("CREATE_TIME");
		this.createUser = rowMapper.getString("CREATE_USER");
	}

	@Transient
	public String getName(){
		return columnName;
	}

	@Transient
	public String getCaption(){
		return columnCaption;
	}

	@Transient
	public boolean getIsRefColumn() {
		boolean isRefColumn = false;
		if(StringUtils.isNotBlank(this.getRefTableName()) && StringUtils.isNotBlank(this.getRefIdColumn()) 
			&&	StringUtils.isNotBlank(this.getRefNameColumn())) {
			isRefColumn = true;
		}
		return isRefColumn;
	}
	/**获取参考表的名称字段的变量名（优先使用别名）
	 * 
	 * @return 
	 * @author wanghua
	 */
	@Transient
	public String getRefNameColumnVarName() {
		String refNameColumn = this.refNameColumn;
		if(StringUtils.isNotBlank(this.refNameColumnAliasName)) {
			refNameColumn = this.refNameColumnAliasName;
		}
		String refNameColumnVarName = SrcCodeUtils.getVarName(refNameColumn);
		return refNameColumnVarName;
	}
	@Transient
	public String getRefNameColumnPropName() {
		String columnName;
		if(StringUtils.isNotBlank(this.refNameColumnAliasName)) {
			columnName = this.refNameColumnAliasName;
		}else {
			columnName = this.refNameColumn;
		}
		String propName = SrcCodeUtils.getPropName(columnName);
		return propName;
	}

	@Transient
	public String getRefNameColumnName() {
		if(StringUtils.isNotBlank(this.refNameColumnAliasName)) {
			return this.refNameColumnAliasName;
		}else {
			return this.refNameColumn;
		}
	}

	/**
	 * 
	 * @return String Integer Long Date Boolean BigDecimal QMoneyYuan QMoneyWanYuan QPercent QKilogram QSquareMeter QCubicMeter
	 * @author wanghua
	 * @reviewer  
	 * @createTime 2021年9月14日 上午10:20:13
	 */
	@Transient
	public String getJavaType() {
		String javaType = "String";

		int precision = this.dataScale==null?0:this.dataScale.intValue();
		int dataLen = this.dataLength == null?0:this.dataLength.intValue();
		if(precision > 0) {
			return "BigDecimal";
		}

		if(StringUtils.isBlank(this.dataType))return javaType;


		String dataType = this.dataType.toLowerCase();

		dataType = dataType.toLowerCase().trim();
		int idx = dataType.indexOf("(");
		if(idx > 0) {
			dataType = dataType.substring(0, idx);
			dataType = dataType.trim();
		}

		if("checkbox".equalsIgnoreCase(this.custDataType)
		|| "boolean".equalsIgnoreCase(this.custDataType)
		|| "switch".equalsIgnoreCase(this.custDataType))
		{
			return "Boolean";
		}
		if ("varchar".equalsIgnoreCase(dataType)||"varchar2".equalsIgnoreCase(dataType)
				|| "clob".equalsIgnoreCase(dataType)
        		|| "text".equalsIgnoreCase(dataType)|| "tinytext".equalsIgnoreCase(dataType)
				|| "mediumtext".equalsIgnoreCase(dataType) || "longtext".equalsIgnoreCase(dataType)
				|| "string".equalsIgnoreCase(dataType)
				|| "char".equalsIgnoreCase(dataType)
				|| "nvarchar".equalsIgnoreCase(dataType)
				|| "nvarchar2".equalsIgnoreCase(dataType)
				|| dataType.contains("character"))
        {
            javaType = "String";
        }else if ("date".equalsIgnoreCase(dataType))
        {
            javaType = "LocalDate";
        }else if ("datetime".equalsIgnoreCase(dataType) || "timestamp".equalsIgnoreCase(dataType) || "time".equalsIgnoreCase(dataType))
        {
            javaType = "LocalDateTime";
        }
		else if("real".equalsIgnoreCase(dataType) || "float".equalsIgnoreCase(dataType) || "double".equalsIgnoreCase(dataType)) {
			javaType = "BigDecimal";
		}else if ("number".equalsIgnoreCase(dataType) || "numeric".equalsIgnoreCase(dataType)
				||"BigDecimal".equalsIgnoreCase(dataType) || "Decimal".equalsIgnoreCase(dataType))
        {
			if(precision == 0) {
				if(dataLen == 1) {
					javaType = "Boolean";
				}
				else if(dataLen <= 8) {
					return javaType = "Integer";
				}else javaType = "Long";
			}else{
				javaType = "BigDecimal";
			}
        }else if ("Integer".equalsIgnoreCase(dataType)||"int".equalsIgnoreCase(dataType)||"int32".equalsIgnoreCase(dataType)
				||"smallserial".equalsIgnoreCase(dataType) 
				||"int2".equalsIgnoreCase(dataType) ||"int4".equalsIgnoreCase(dataType)
				||"smallint".equalsIgnoreCase(dataType)||"tinyint".equalsIgnoreCase(dataType)
				||"byte".equalsIgnoreCase(dataType))
        {
			if(dataLen == 1) {
				javaType = "Boolean";
			}else {
				javaType = "Integer";
			}
        }else if ("Long".equalsIgnoreCase(dataType)||"bigint".equalsIgnoreCase(dataType)
				||"bigserial".equalsIgnoreCase(dataType) ||"serial".equalsIgnoreCase(dataType)
				||"int8".equalsIgnoreCase(dataType)||"int64".equalsIgnoreCase(dataType))
        {
            javaType = "Long";
        }
        else if ("boolean".equalsIgnoreCase(dataType) || "bool".equalsIgnoreCase(dataType))
        {
            javaType = "Boolean";
        }
		else if ("yuan".equalsIgnoreCase(dataType))
		{
			javaType = "QMoneyYuan";
		}
        return javaType;
	}

	@Transient
	public String getJsType(){
		String javaType = this.getJavaType();
		if("String".equalsIgnoreCase(javaType))return "string";
		if("LocalDate".equalsIgnoreCase(javaType))return "string";
		if("LocalDateTime".equalsIgnoreCase(javaType))return "string";
		if("Boolean".equalsIgnoreCase(javaType))return "boolean";
		if(getIsNumber())return "number";
		return "string";
	}

	/**所有整数类型
	 *
	 * @author wanghua
	 * @date 2021/11/5  12:20
	 * @return boolean
	 **/
	@Transient
	public boolean getIsIntegerNumber(){
		String javaType = this.getJavaType();
		if("Byte".equalsIgnoreCase(javaType))return true;
		if("Short".equalsIgnoreCase(javaType))return true;
		if("Integer".equalsIgnoreCase(javaType))return true;
		if("Long".equalsIgnoreCase(javaType))return true;
		return false;
	}
	/**所有浮点数类型和整数类型
	 *
	 * @author wanghua
	 * @date 2021/11/5  12:20
	 * @return boolean
	 **/
	@Transient
	public boolean getIsNumber(){
		String javaType = this.getJavaType();
		if("Byte".equalsIgnoreCase(javaType))return true;
		if("Short".equalsIgnoreCase(javaType))return true;
		if("Integer".equalsIgnoreCase(javaType))return true;
		if("Long".equalsIgnoreCase(javaType))return true;
		if("BigDecimal".equalsIgnoreCase(javaType))return true;
		if("Double".equalsIgnoreCase(javaType))return true;
		if("Float".equalsIgnoreCase(javaType))return true;
		if(javaType.startsWith("Q"))return true;
		return false;
	}
	/**首字母小写的变量名
	 * 
	 * @return 
	 * @author wanghua
	 */
	@Transient
	public String getVarName() {
		String columnName = this.columnAliasName;//优先使用别名
		if(StringUtils.isBlank(columnName)){
			columnName = this.columnName;
		}
		if(columnName == null)return "";
		columnName = columnName.trim().toUpperCase();
		
		while(columnName.startsWith("_")) columnName = columnName.substring(1);
		while(columnName.endsWith("_")) columnName = columnName.substring(0, columnName.length()-1);
		String varName = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, columnName);
		return varName;
	}
	
	/**返回用于表格组件显示的字段名
	 * 
	 * @return
	 */
	@Transient
	public String getGridFieldName() {
		if(columnName.toUpperCase().endsWith("_ID") && columnName.length() >3) {
			String aliasName = columnName.substring(0, columnName.length() - 3) +"_NAME";
			String varName = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, aliasName);
			return varName; 
		}else {
			return this.getVarName();
		}
	}
	
	/**首字母小写的变量名,如果返回值以Id结尾，则去掉Id
	 * 
	 * @return 
	 * @author wanghua
	 */
	@Transient
	public String getVarNameTrimId() {
		String varName = this.getVarName();
		if(varName.endsWith("Id")) {
			varName = varName.substring(0, varName.length() - 2);
		}
		return varName;
	}
	
	/**把以"_ID"结尾的字段名，变为以"_NAME"结尾的字段名，并返回对应的变量名
	 * 
	 * @return
	 */
	@Transient
	public String getRefIdColumnAliasName() {
		if(columnName.toUpperCase().endsWith("_ID") && columnName.length() >3) {
			String aliasName = columnName.substring(0, columnName.length() - 3) +"_NAME";
			return aliasName;
		}else return columnName;
	}
	
	/**把以"_ID"结尾的字段名，变为以"_NAME"结尾的字段名，并返回对应的变量名
	 * 
	 * @return
	 */
	@Transient
	public String getVarNameOfRefIdColumnAliasName() {
		String aliasName = getRefIdColumnAliasName();
		String varName = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, aliasName);
		return varName; 
	}
	/**首字母大写的变量名
	 * 
	 * @return 
	 * @author wanghua
	 */
	@Transient
	public String getPropName() {
		String columnName = this.columnAliasName;//优先使用别名
		if(StringUtils.isBlank(columnName)){
			columnName = this.columnName;
		}
		if(columnName == null)return "";
		columnName = columnName.trim().toUpperCase();
		
		while(columnName.startsWith("_")) columnName = columnName.substring(1);
		while(columnName.endsWith("_")) columnName = columnName.substring(0, columnName.length()-1);
		String varName = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, columnName);
		return varName;
	}

	/**首字母大写的变量名,如果返回值以Id结尾，则去掉Id
	 * 
	 * @return 
	 * @author wanghua
	 */
	@Transient
	public String getPropNameTrimId() {
		String propName = this.getPropName();
		if(propName.endsWith("Id")) {
			propName = propName.substring(0, propName.length() - 2);
		}
		return propName;
	}
	
	@Transient
	public boolean getIsKeyColumn() {
		return "ID".equalsIgnoreCase(this.columnName) || "OID".equalsIgnoreCase(this.columnName)  || "1".equals(this.columnType);
	}

	@Transient
	public boolean getJsonIgnore() {
		if(ColumnType.TENANT_COLUMN.equals(this.columnType))return true;
		boolean jsonIgnore = false;
		if("RECORD_CREATE_TIME".equalsIgnoreCase(columnName)) {
			jsonIgnore = true;
		}else if("RECORD_UPDATE_TIME".equalsIgnoreCase(columnName)) {
			jsonIgnore = true;
		}else if("RECORD_CREATE_USER".equalsIgnoreCase(columnName)) {
			jsonIgnore = true;
		}else if("RECORD_UPDATE_USER".equalsIgnoreCase(columnName)) {
			jsonIgnore = true;
		}else if("CREATE_TIME".equalsIgnoreCase(columnName)) {
			jsonIgnore = true;
		}else if("UPDATE_TIME".equalsIgnoreCase(columnName)) {
			jsonIgnore = true;
		}else if("CREATE_USER".equalsIgnoreCase(columnName)) {
			jsonIgnore = true;
		}else if("UPDATE_USER".equalsIgnoreCase(columnName)) {
			jsonIgnore = true;
		}else if("RECORD_EDIT_FLAG".equalsIgnoreCase(columnName)) {
			jsonIgnore = true;
		}else if("LOGIC_DELETE_FLAG".equalsIgnoreCase(columnName)) {
			jsonIgnore = true;
		}else if("TENANT_ID".equalsIgnoreCase(columnName)) {
			jsonIgnore = true;
		}else if("TENANT_ID_".equalsIgnoreCase(columnName)) {
			jsonIgnore = true;
		}
		return jsonIgnore;
	}
	
	@Transient
	public boolean getMaybeFormField() {
		if(getJsonIgnore())return false;
		if(this.getIsKeyColumn())return false;
		if("ROW_LOCK".equalsIgnoreCase(this.columnName))return false;
		return true;
	}
	
	/**DAYU-CODE-009
	 * "1 普通文本"
	 * "2 带颜色小标签"
	 * "3 ICON+文字"
	 * "4 带下拉菜单的文本"
	 * "5 评分"
	 * "6 图片"
	 * @return 
	 * @author wanghua
	 * @reviewer  
	 * @createTime 2021年9月14日 上午10:00:58
	 */
	@Transient
	public String getDefaultCellTextType() {
		if(StringUtils.isNoneBlank(this.codeType))return "2";
		return "1";
	}
	
	/**输入框类型 DAYU-CODE-011
	 * "1 单行文本框" ，
	 * "2 下拉框" ，
	 * "3 整型数" ，
	 * "4 浮点数" ，
	 * "5 百分比" ，
	 * "6 单个图片" ，
	 * "7 多个图片" ，
	 * "8 单个附件" ，
	 * "9 多个附件" ，
	 * "10 多行文本框" ，
	 * "11 日期" ，
	 * "12 日期+时间" ，
	 * "15 单选按钮组" ，
	 * "16 单个勾选框" ，
	 * "17 多个勾选框" ，
	 * "18 颜色框"
	 * @return 
	 * @author wanghua
	 * @reviewer  
	 * @createTime 2021年9月14日 上午10:16:59
	 */
	@Transient
	public String getDefaultInputElementType() {
		if(StringUtils.isNoneBlank(this.codeType))return FormElementType.SELECT;
		if("rate".equalsIgnoreCase(this.custDataType))return FormElementType.SCORE_RATE;
		if("checkbox".equalsIgnoreCase(this.custDataType))return FormElementType.CHECKBOX;
		if("check".equalsIgnoreCase(this.custDataType))return FormElementType.CHECKBOX;
		if("boolean".equalsIgnoreCase(this.custDataType))return FormElementType.CHECKBOX;
		if("radios".equalsIgnoreCase(this.custDataType))return FormElementType.RADIOS;
		if("file".equalsIgnoreCase(this.custDataType))return FormElementType.ONE_FILE;
		if("img".equalsIgnoreCase(this.custDataType))return FormElementType.ONE_IMAGE;
		if("percent".equalsIgnoreCase(this.custDataType))return FormElementType.PERCENT_INPUT;
		if("datetime".equalsIgnoreCase(this.custDataType))return FormElementType.DATE_TIME;
		if("switch".equalsIgnoreCase(this.custDataType))return FormElementType.SWITCH;
		if("tree".equalsIgnoreCase(this.custDataType))return FormElementType.TREE_SELECT;
		if("cascader".equalsIgnoreCase(this.custDataType))return FormElementType.CASCADER;

		String javaType = getJavaType();//String Integer Long Date Boolean BigDecimal QMoneyYuan QMoneyWanYuan QPercent QKilogram QSquareMeter QCubicMeter
		if("Integer".equals(javaType) || "Long".equals(javaType))return FormElementType.INTEGER_INPUT;
		if("QPercent".equals(javaType) )return FormElementType.PERCENT_INPUT;
		if("BigDecimal".equals(javaType) || javaType.startsWith("Q"))return FormElementType.FLOAT_INPUT;
		if("LocalDate".equals(javaType) )return  FormElementType.DATE;
		if("LocalDateTime".equals(javaType) )return  FormElementType.DATE_TIME;
		if("Boolean".equals(javaType) )return FormElementType.CHECKBOX;
		if(dataLength != null && dataLength>200)return FormElementType.MULTI_LINE_TEXT;
		return FormElementType.TEXT_INPUT;
	}

	private String columnType;
	public static final String ColumnTypeCode = "DAYU-CODE-007";
	/**
	 * 字段类型，1主键字段，2外键字段，3名称字段，4父ID字段，5租户字段，0普通字段
	 * @return
	 * @author wanghua
	 */
	@Transient
	public String getColumnType() {
		return columnType;
	}
	public void setColumnType(String columnType) {
		this.columnType = columnType;
	}

	@Transient
	public String getColumnTypeCaption() {
		return DictAll.getCachedItemName(ColumnTypeCode, columnType);
	}

	@Transient
	public boolean getSortable(){
		String javaType = this.getJavaType();
		if(!"String".equals(javaType)){
			return true;
		}else{
			if(StringUtils.isNotBlank(this.getCodeType())){
				return true;
			}else{
				return dataLength==null || dataLength < 65;
			}
		}
	}
	@Transient
	public boolean getIsDate(){
		String javaType = this.getJavaType();
		return "LocalDate".equals(javaType);
	}
	@Transient
	public boolean getIsDateTime(){
		String javaType = this.getJavaType();
		return "LocalDateTime".equals(javaType);
	}
	
	@Transient
	public boolean getHasCodeType() {
		return StringUtils.isNotBlank(codeType);
	}

	@Override
	public boolean equals(Object obj) {
		if(obj == null)return false;
		if(id == null)return false;
		DataColumn other = (DataColumn)obj;
		return id.equals(other.id);
	}

	@Override
	public int hashCode() {
		if(id == null)return 0;
		return id.hashCode();
	}
}
